package com.itfreer.ui.base;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;

import com.itfreer.ui.R;
import com.itfreer.ui.base.api.IPower;

/**
 * 自定义GridView，解决分割线的问题
 */
public class GridView extends android.widget.GridView implements IPower {

    private String securityID;
    private boolean securityVisible=true;

    public GridView(Context context) {
        super(context);
    }

    public GridView(Context context, AttributeSet attrs) {
        super(context, attrs);
        getAttrs(context, attrs);
    }

    public GridView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        getAttrs(context, attrs);
    }

    protected void getAttrs(Context context, AttributeSet attrs){
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SimpleView);
        securityID = a.getString(R.styleable.SimpleView_securityID);
    }

    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
                MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);
    }

    /**
     * 获取权限ID
     * @return
     */
    public String getSecurityID(){
        return securityID;
    }

    /**
     * 没有权限时，设置是否可见
     * @param visible
     */
    public void setSecurityVisible(boolean visible){
        securityVisible = visible;
        if(visible){
            this.setVisibility(View.VISIBLE);
        }else{
            // 表示不可见并且不占用空间
            this.setVisibility(View.GONE);
        }
    }
}